﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SD.LLBLGen.Pro.ORMSupportClasses;
using Northwinddemo.DAL.EntityClasses;
using Northwinddemo.BusinessLayer.Repository.Abstract;
using MvcContrib.Pagination;

namespace Northwinddemo.Web.Tests.Repository
{
    class FakeProductsRepository : FakeNorthwindRepository<ProductsEntity>, IProductsRepository
    {
        public FakeProductsRepository(ProductsEntity product)
            : base(product)
        {
        }

        public FakeProductsRepository(ProductsEntity[] products)
            : base(products)
        {
        }

        public override ProductsEntity GetById(int id, IDataAccessAdapter adapter)
        {
            return (from p in entities
                    where p.ProductId == id
                    select p).Single();
        }

        public override IList<ProductsEntity> GetAll(IDataAccessAdapter adapter)
        {
            return (from p in entities
                    select p).ToList();
        }

        public IPagination<ProductsEntity> GetBySearchOrderByProductNamePrefetchSupplierAndCategory(string search, int? page)
        {
            return (from p in entities
                    where p.ProductName.Contains(search)
                    orderby p.ProductName
                    select p).AsPagination(page ?? 1, 10);
        }

    }
}
